package deepseek.deepseekr1.controller;


import deepseek.deepseekr1.service.MessageService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequiredArgsConstructor
public class MessageController {

    private final MessageService messageService;


    @GetMapping("/hello")
    public String hello(HttpServletRequest request, @RequestParam(required = false) String content) {
        return messageService.askMessage(content, request);
    }


//    @GetMapping("/api/stream-chat")
//    public Flux<ServerSentEvent<String>> streamChat() {
//        WebClient client = WebClient.create("http://localhost:11434/api/chat");
//
//        return client.post()
//                .contentType(MediaType.APPLICATION_JSON)
//                .bodyValue("""
//                            {
//                                "model": "deepseek-r1:32b",
//                                "messages": [{"role": "user", "content": "如何获得到同事购买的草莓"}],
//                                "stream": true
//                            }
//                        """)
//                .retrieve()
//                .bodyToFlux(String.class)
//                .map(data -> ServerSentEvent.builder(data).build())
//                .onErrorResume(e -> Flux.just(
//                        ServerSentEvent.builder("Error: " + e.getMessage()).build()
//                ));
//    }


}
